#!/usr/bin/env python
# -*-coding:UTF-8-*-


data = {'admin': {'pwd': 'pass', 'balance': 5000, 'tel': '12345678', 'is_lock': 0}, }


def login():
    user = input('\n请输入用户名:\n')
    pwd = input('\n请输入密码：\n')
    if user in data.keys():
        if data[user]['is_lock'] < 3:
            if pwd == data[user]['pwd']:
                data[user]['is_lock'] = 0
                print('\n登录成功!\n')
                return user
            else:
                data[user]['is_lock'] += 1
                print('\n用户名或密码错误。\n')
        else:
            print('用户已锁定！请联系美女客服。')
    else:
        print('\n用户名或密码错误。\n')
    return False


def reg():
    user = input('\n请输入用户名:\n')

    if user in data.keys():
        print('用户已存在!')
    else:
        pwd = input('\n请输入密码：\n')
        tel = input('\n请输入电话：\n')
        data[user] = {'pwd': pwd, 'balance': 5000, 'tel': tel, 'is_lock': 0}
        print('用户%s注册成功！' % user)


def transfer(user, user1, num):
    balance = data[user]['balance']
    if int(num) > balance:
        print('余额不足！')
    else:
        data[user]['balance'] = balance - num
        data[user1]['balance'] += num
        print('转账成功！')

def draw_moey(user, num):
    balance = data[user]['balance']
    if int(num) > balance:
        print('余额不足！')
    else:
        data[user]['balance'] = balance - num
        print('取款成功，请拿好！')



def menu():
    while True:
        login_user = login()
        if login_user:
            break
    while True:
        user_input = input('''
        应用菜单：
        1、用户注册
        2、余额查询
        3、账号取款
        4、账号转账
        5、退出系统
        
请选择：       
        ''')
        try:
            if user_input == '1':
                reg()
            elif user_input == '2':
                print('用户余额：%s' % data[login_user]['balance'])
            elif user_input == '3':
                num = input('请输入取款金额:\n')
                draw_moey(login_user, int(num))
            elif user_input == '4':
                user1 = input('请输入目标账户:\n')
                num = input('请输入转账金额:\n')
                transfer(login_user, user1, int(num))
            elif user_input == '5':
                break
            else:
                print('输入错误。')
        except Exception as e:
            print('输入错误。')


def main():
    print('欢迎使用马哥银行ATM系统！')
    print('***这是一个走失的管理员和密码 admin pass ***')
    while True:
        menu()


if __name__ == '__main__':
    main()
    """
    if else 这些考虑下可以用：
    case = input("Please input a case: ")
    switch = {'1': 'case 1', '2': 'case 2', '3': 'case 3'}
    print(switch.get(case,'Invalid input'))
    可以不？
    """
